package com.UdpRecieve.controller.system;

import com.UdpRecieve.domain.system.SysUser;
import com.UdpRecieve.framework.annotation.LogAnnotion;
import com.UdpRecieve.framework.enums.BusinessType;
import com.UdpRecieve.framework.page.TableDataInfo;
import com.UdpRecieve.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/SysUserPage")
public class UserController extends BaseController{

    @Autowired
    private SysUserService sysUserService;

    @GetMapping()
    public ModelAndView toSysUserPage(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("system/sysUserPage");
        return mv;
    }

    @GetMapping("/ryUser")
    public ModelAndView toRyUser(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("system/ryUser");
        return mv;
    }

    /**
     * 查询用户列表
     * @param sysUser
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo selectUserList(SysUser sysUser){
        startPage();
        List<SysUser> sysUserList =  sysUserService.selectUserList(sysUser);
        return getDataTable(sysUserList);
    }

    /**
     * 重置密码
     * @param sysUser
     * @return
     */
    @PostMapping("/rePassword")
    @LogAnnotion(title = "系统管理_用户管理",businessType = BusinessType.RPASSWORD)
    @ResponseBody
    public ModelMap rePassword(SysUser sysUser){
        ModelMap m = new ModelMap();
        int i = sysUserService.rePassword(sysUser);
        if (i!=-1){
            m.addAttribute("result","成功");
        }else{
            m.addAttribute("result","失败");
        }

        return m;
    }

}
